package com.example.redistempalte.Publisher;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Calendar;

@Component
public class MsgPublisher {

    private Logger logger = LoggerFactory.getLogger(MsgPublisher.class);

    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Resource
    private ChannelTopic topic;
    //private ChannelTopic topic=new ChannelTopic("pubsub:queue");

    public void sendMsg(String msg){
        redisTemplate.convertAndSend( topic.getTopic(), "Message: " + msg +
                ";Time:" + Calendar.getInstance().getTime());
    }
}